//
//  JSTInterestcircleImageView.m
//  KYKJPackDemo
//
//  Created by 01 on 17/5/11.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "JSTInterestcircleImageView.h"
#import "JSTInterestcircleDataModel.h"
#import "JSTInterestcircleImageFrame.h"

@implementation JSTInterestcircleImageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

- (void)setImageFrame:(JSTInterestcircleImageFrame *)imageFrame
{
    _imageFrame = imageFrame;
    self.frame = _imageFrame.frame;
    
    // 取出网络图片数据
    JSTInterestcircleDataModel *model = imageFrame.model;
    // 先移除在创建
    for (UIView *obj in self.subviews)
    {
        [obj removeFromSuperview];
    }
    [model.contentImgUrlArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
    {
        UIImageView *imgView = [[UIImageView alloc] init];
        imgView.userInteractionEnabled = YES;
        imgView.tag = 100 + idx;
        CGFloat imageX = kCurrentScreenWidth(10) + ((kDeviceWidth - kCurrentScreenWidth(10))/3.)*idx;
        CGFloat imageY = 0;
        CGFloat imageW = ((kDeviceWidth - kCurrentScreenWidth(10))/3.) - kCurrentScreenWidth(10);
        CGFloat imageH = imageW;
        imgView.frame = CGRectMake(imageX, imageY, imageW, imageH);
        
        //描边
        imgView.layer.borderWidth=0.5;
        imgView.layer.borderColor=kANGSeparateLineColor.CGColor;
        //设置不拉伸
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        imgView.clipsToBounds = YES;
        //添加手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [imgView addGestureRecognizer:tap];
        
        [imgView setImageWithURL:[NSURL URLWithString:obj]];
        [self addSubview:imgView];
    }];
}

#pragma mark 点击图片放大
- (void) tapClick:(UITapGestureRecognizer *)tap
{
    UIImageView *tapImageView = (UIImageView *)tap.view;
    
    [JSTScanImage scanBigImageWithImageView:tapImageView];
}
@end
